package com.ligoudan.converter;

import com.ligoudan.model.GenImageModel;

import java.util.Properties;
import java.util.logging.Logger;

public class Converter {

    private static final Logger LOGGER = Logger.getLogger(Converter.class.getName());


    public static Properties model2Config(GenImageModel model) {
        Properties config = new Properties();
        config.setProperty("maxWidth", String.valueOf(model.getMaxWidth()));
        config.setProperty("filename", model.getFilename());
        config.setProperty("filePath", model.getFilePath());
        return config;
    }

    public static GenImageModel config2Model(Properties config) {
        GenImageModel model = new GenImageModel();
        int maxWidth;
        try {
            maxWidth = Integer.parseInt(config.getProperty("maxWidth", "1000"));
        } catch (NumberFormatException e) {
            e.printStackTrace();
            maxWidth = 1000;
        }
        model.setMaxWidth(maxWidth);
        model.setFilename(config.getProperty("filename", "out.png"));
        model.setFilePath(config.getProperty("filePath", ""));
        return model;
    }

}
